<?php

namespace common\component;


use yii\base\Model;

class BaseModel extends Model
{

    /**
     * 获取验证错误信息
     * @param bool $single
     * @return String
     */
    public function getErrorsToString($single = true) {
        $errors = $this->getErrors();
        $errString = "";
        if (count($errors)) {
            foreach ($errors as $key => $errs) {
                if ($single) {
                    $errString = $errs[0];
                    break;
                } else {
                    foreach ($errs as $err) {
                        $errString .= $err;
                    }
                }
            }
        }
        else {
            $errString = "系统异常错误";
        }
        return $errString;
    }
}